Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zkochan-drivelist

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zkochan-drivelist

List all connected drives in your computer, in all major operating systems

  • 0.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

drivelist

List all connected drives in your computer, in all major operating systems.

Current Release License Downloads Travis CI status AppVeyor status Dependency status Gitter Chat

Notice that this module does not require admin privileges to get the drives in any supported operating system.

Supports:

  • Windows.
  • GNU/Linux distributions that include util-linux and udev.
  • Mac OS X.

The drivelist core consists of a set of scripts built with technologies that are available by default on the target operating systems (like Bash, VBScript, etc). Each of these scripts attempts to get information about the available drives (and metadata related to them), using any methods the target platform provides, like a combination of diskutil, /proc/mounts, etc. You can find these scripts in the scripts/ directory.

The scripts are then expected to print to stdout all the drive information they have gathered in a predefined way, based on the YAML language. The scripts are expected to output a set of blocks (separated by blank lines), each representing a drive with a set of key/value pairs. The exact keys that we expect are constantly changing while we keep improving this module, but you can see what the currently expected keys are by running the platform script that corresponds to your operating system.

This is how the raw output looks on my MacBook Pro at the time of this writing:

$ ./scripts/darwin.sh
device: /dev/disk0
displayName: /dev/disk0
description: "APPLE SSD SM0256G"
size: 251000193024
mountpoints: []
raw: /dev/rdisk0
protected: False
system: True

device: /dev/disk1
displayName: /dev/disk1
description: "Macintosh HD"
size: 249779191808
mountpoints:
  - path: /
raw: /dev/rdisk1
protected: False
system: True

Because of the simplicity of this module's design, supporting a new operating system simply means adding a new script to scripts/ that gathers drive data and outputs something similar to the above example. The challenge with this is that we must ensure all the platform scripts print consistent output.

When the user executes drivelist.list(), the module checks the operating system of the client, and executes the corresponding drive scanning script as a child process. It then parses the YAML output of the script as an array of objects, and returns that to the user.

Examples (the output will vary depending on your machine):

const drivelist = require('drivelist');

drivelist.list((error, drives) => {
  if (error) {
    throw error;
  }

  console.log(drives);
});

Mac OS X:

[
  {
    device: '/dev/disk0',
    displayName: '/dev/disk0',
    description: 'GUID_partition_scheme',
    size: 68719476736,
    mountpoints: [
      {
        path: '/'
      }
    ],
    raw: '/dev/rdisk0',
    protected: false,
    system: true
  },
  {
    device: '/dev/disk1',
    displayName: '/dev/disk1',
    description: 'Apple_HFS Macintosh HD',
    size: 68719476736,
    mountpoints: [],
    raw: '/dev/rdisk0',
    protected: false,
    system: true
  }
]

GNU/Linux

[
  {
    device: '/dev/sda',
    displayName: '/dev/sda',
    description: 'WDC WD10JPVX-75J',
    size: 68719476736,
    mountpoints: [
      {
        path: '/'
      }
    ],
    raw: '/dev/sda',
    protected: false,
    system: true
  },
  {
    device: '/dev/sdb',
    displayName: '/dev/sdb',
    description: 'DataTraveler 2.0',
    size: 7823458304,
    mountpoints: [
      {
        path: '/media/UNTITLED'
      }
    ],
    raw: '/dev/sdb',
    protected: true,
    system: false
  }
]

Windows

[
  {
    device: '\\\\.\\PHYSICALDRIVE0',
    displayName: 'C:',
    description: 'WDC WD10JPVX-75JC3T0',
    size: 68719476736,
    mountpoints: [
      {
        path: 'C:'
      }
    ],
    raw: '\\\\.\\PHYSICALDRIVE0',
    protected: false,
    system: true
  },
  {
    device: '\\\\.\\PHYSICALDRIVE1',
    displayName: 'D:, F:',
    description: 'Generic STORAGE DEVICE USB Device',
    size: 7823458304,
    mountpoints: [
      {
        path: 'D:'
      },
      {
        path: 'F:'
      }
    ],
    raw: '\\\\.\\PHYSICALDRIVE1',
    protected: true,
    system: false
  },
  {
    device: '\\\\.\\PHYSICALDRIVE2',
    displayName: '\\\\.\\PHYSICALDRIVE2',
    description: 'Silicon-Power2G',
    size: 2014314496,
    mountpoints: [],
    raw: '\\\\.\\PHYSICALDRIVE2',
    protected: false,
    system: false
  }
]

Installation

Install drivelist by running:

$ npm install --save drivelist

Documentation

drivelist.list(callback)

Kind: static method of drivelist
Summary: List available drives
Access: public

ParamTypeDescription
callbackfunctioncallback (error, drives)

Example

const drivelist = require('drivelist');

drivelist.list((error, drives) => {
  if (error) {
    throw error;
  }

  drives.forEach((drive) => {
    console.log(drive);
  });
});

Tests

Run the test suite by doing:

$ npm test

Contribute

We're looking forward to support more operating systems. Please raise an issue or even better, send a PR to increase support!

Before submitting a PR, please make sure that you include tests, and that the linter runs without any warning:

$ npm run lint

Execute the following command after making any changes to the platform scripts:

npm run compile-scripts

Support

If you're having any problem, please raise an issue on GitHub.

License

The project is licensed under the Apache 2.0 license.

Keywords

FAQs

Package last updated on 30 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc